package md.lanjing.com.module_home.contact;

import android.content.Context;

import com.lxh.baselibray.base.BaseResponce;
import com.lxh.baselibray.constant.Constant;
import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;


import md.lanjing.com.module_home.api.HomeApiService;
import md.lanjing.com.module_home.bean.CartonResponce;
import md.lanjing.com.module_home.bean.HomeRankResponse;
import md.lanjing.com.module_home.bean.NoticeResponse;
import md.lanjing.com.module_home.bean.UserInfoResponce;
import retrofit2.Call;
import retrofit2.Response;

public class HomeContact {
    public static class HomePresent extends BasePresent<IHomeView> {
        public void getNotice(final Context context){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            service.getNotice().enqueue(new NetCallBack<NoticeResponse>() {
                @Override
                public void onSuccess(Call<NoticeResponse> call, Response<NoticeResponse> response) {
                    if (getView()!=null){
                        getView().getNoticeData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }




        public void getRank(final Context context, int pageNo){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            service.getHomeRank(pageNo).enqueue(new NetCallBack<HomeRankResponse>() {
                @Override
                public void onSuccess(Call<HomeRankResponse> call, Response<HomeRankResponse> response) {
                    if (getView()!=null){
                        getView().getRankData(response);

                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }

        public void getUserInfo(final Context context){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            service.getUserInfo(userId).enqueue(new NetCallBack<UserInfoResponce>() {
                @Override
                public void onSuccess(Call<UserInfoResponce> call, Response<UserInfoResponce> response) {
                    if (getView()!=null){
                        getView().getUserInfoData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }

        public void getCarton(final Context context){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            service.getCarcon(userId).enqueue(new NetCallBack<CartonResponce>() {
                @Override
                public void onSuccess(Call<CartonResponce> call, Response<CartonResponce> response) {
                    if (getView()!=null){
                        getView().getCartonData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }
        public void receiveCarton(final Context context, String profitId){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            service.receiveCarton(profitId).enqueue(new NetCallBack<BaseResponce>() {
                @Override
                public void onSuccess(Call<BaseResponce> call, Response<BaseResponce> response) {
                    if (getView()!=null){
                        getView().getReceiveCartonData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }
    }

    public interface IHomeView extends IBaseView {
        void getNoticeData(Response<NoticeResponse> response);
        void getRankData(Response<HomeRankResponse> response);
        void getUserInfoData(Response<UserInfoResponce> response);
        void getCartonData(Response<CartonResponce> response);
        void getReceiveCartonData(Response<BaseResponce> response);
    }
}
